ColdFusion Article

Creating Globalized ColdFusion Applications


Table of Contents

  1. Introduction
  2. Globalization Changes in ColdFusion MX
  3. Good Practices: Obstacles in Developing I18N Applications
  4. Good Practices (cont): Encoding, Unicode, HTML
  5. Good Practices (cont): Locale Determination, Locale-Specific Formatting, Time Zones
  6. Good Practices (cont): ResourceBundles,Application Framework, User Specific, Server Specific

ResourceBundles

Your application should use ResourceBundles to completely separate text and text presentation from application code. ResourceBundles are a concept borrowed from the Java world and consist of locale-based files of key/value pairs, where the key is some text label and the value is that locale’s translation of that key. For example, a U.S. English ResourceBundle might have an entry for cancelBttn=Cancel. A corresponding German ResourceBundle would contain cancelBttn=Abbrechen.

While I sometimes extend the meaning of ResourceBundles to include database tables and XML files, this discussion will focus on files. My personal definition of ResourceBundle files specifically uses UTF-8 character encoding, which differs from Java where ResourceBundles are strictly ANSI encoded files. Any Unicode characters in Java ResourceBundles are encoded as plain ANSI text: /uxxxx, where xxxx refers to that character’s unicode representation. That style of encoding obviously places an extra burden on ColdFusion to process the ResourceBundle, so I recommend sticking with the UTF-8 encoding style. As an added benefit, the UTF-8 encoded ResourceBundles are easy to read.

In your application, separate ResourceBundle files into logical groupings (for instance, menu.properties, mapFrame.properties, login.properties and so forth) and then again into locale-specific files within those groupings (menu_en_US.properties, menu_fr_FR.properties, and so on). The application’s init routine will read these files and assign the resulting data to a shared scope. There is a resourceBundleCFC in the Macromedia Exchange that can help you with this process.

And that brings us to the final part of this article, how to structure your application framework.

Application Framework

How you structure your application’s framework depends on how you will roll out your application. There is no right or wrong way to approach this. In general, G11N application frameworks can be split into two basic groups: user specific and server specific.

User Specific

The most economical approach is "one" ColdFusion server and one database on one domain to handle all the locales planned for an application. I use the term "one" ColdFusion server here but this could easily be a cluster of ColdFusion servers. Locale-based content is not specific to any particular server, location, or domain. You serve content based on each user’s locale. All supported locale-specific content is maintained on all servers. The application should retain each user’s locale information as a session variable, cookie, or appended to each URL. Use locale-content caching as much as practical. In this approach, your application would use the setLocale() function in the Application.cfm file to assign the ColdFusion server a locale on each page request, provided that ColdFusion supports the locale.

Server Specific

This type of application framework holds content in a specific location, such as a domain, server (or server instance), directory, and so forth. A user that requires a specific locale is directed to a specific location, for instance, for fr.weWantYourMoney.com redirects to www.weWantYourMoney.com/fr, and so forth. This approach obviously requires more resources but is more appropriate for allocating resources as needed on a per-locale basis. All locale references are hard-coded for each location.

Conclusion

I hope this article has helped you start thinking about globalizing your ColdFusion applications and that the "good practices" I’ve outlined will prove valuable to your applications. It is a big world out there.